<?php
/*
*All rights reserved: Json.
*Links:http://www.liyaoquan.cn.
*Links:http://imarkchina.cn.
*Links:http://www.imarkchina.cn.
*/

/**
 * 博客前台日志/专题显示模型，负责数据，增，删，改，查
 * 因为没有博客数据没使用数据库，所以没有继承 Model 类
 */
Class ShowModel extends PublicModel{

	/**
	 * 取日志内容 返回
	 * @param  [type] $id [description]
	 * @return [type]     [description]
	 */
	Public function showPost($id){
		@$file = unfile(C('post.postdata').$id.'.Mark');
		if (!$file) {
			return false;
		}
		if (!file_exists(C('pinglun.id').$id.'.php')) {
			varfile(C('pinglun.id').$id.'.php', array());
		}
		$listidfile = loadfile(C('post.postid').$file['listid'].'.php');
		$postid = array_keys($listidfile);
		$i = 1;
		$tempid = array();
		foreach ($postid as $k => $v) {
			$tempid[($k + 1)] = $v;
		}
		$keyid = array();
		foreach ($tempid as $k => $v) {
			$keyid[$v] = $k;
		}
		$chekid = $keyid[$id];
		if ($chekid == 1) {
			$lasttitle = false;
		}else {
			$getntxpost = $chekid - 1;
			$chekcfile = unfile(C('post.postdata').$tempid[$getntxpost].'.Mark');
			$lasttitle['id'] = $chekcfile['id'];
			$lasttitle['title'] = $chekcfile['title'];
		}
		if ($chekid == count($keyid)) {
			$nettitle = false;
		} else {
			$getntxpost = $chekid + 1;
			$chekcfile = unfile(C('post.postdata').$tempid[$getntxpost].'.Mark');
			$nettitle['id'] = $chekcfile['id'];
			$nettitle['title'] = $chekcfile['title'];
		}
		$redata['check'] = $this->CheckIsOpen();
		$redata['file'] = $file;
		$redata['getnext'] = $nettitle;
		$redata['getlast'] = $lasttitle;
		return $redata;
	}

	/**
	 * 取专题内容 返回
	 * @param  [type] $id [description]
	 * @return [type]     [description]
	 */
	Public function showPage($id){
		@$file = unfile(C('page.data').$id.'.Mark');
		if (!$file) {
			return false;
		}
		if (!file_exists(C('pinglun.id').$id.'.php')) {
			varfile(C('pinglun.id').$id.'.php', array());
		}
		return $file;
	}

	/**
	 * 添加日志浏览次数
	 * @param  [type] $id [description]
	 * @return [type]     [description]
	 */
	Public function hits($id){
		$hits = loadfile(C('hits'));
		if (!empty($hits[$id])) {
			$hits[$id] = $hits[$id] + 1;
			varfile(C('hits'), $hits);
		}
	}
}